package com.lill.system.web;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lill.common.component.util.PageUtils;
import com.lill.common.component.util.Query;
import com.lill.common.component.util.R;
import com.lill.support.annotation.CurrentUser;
import com.lill.system.model.SysMsgModelInfoEntity;
import com.lill.system.model.SysUserEntity;
import com.lill.system.service.ISysMsgModelInfoService;

/**
 * 消息模板Controller
 *
 * @author lill
 * @date 2020-04-09 18:08:25
 */
@RestController
@RequestMapping("sys/msgmodelinfo")
public class SysMsgModelInfoController {
    @Autowired
    private ISysMsgModelInfoService msgModelInfoService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("msgmodelinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<SysMsgModelInfoEntity> msgModelInfoList = msgModelInfoService.queryList(query);
        int total = msgModelInfoService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(msgModelInfoList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("msgmodelinfo:info")
    public R info(@PathVariable("id") String id) {
    	SysMsgModelInfoEntity msgModelInfo = msgModelInfoService.queryObject(id);

        return R.ok().put("msgModelInfo", msgModelInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("msgmodelinfo:save")
    public R save(@RequestBody SysMsgModelInfoEntity msgModelInfo,@CurrentUser SysUserEntity user) {
    	msgModelInfo.setStatus(1);
    	msgModelInfo.setCreateUser(user.getId());
    	msgModelInfo.setCreateTime(new Date());
        int result=msgModelInfoService.save(msgModelInfo);
		if(result>0){
        	return R.ok();
        }else{
        	return R.failure();
        }
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("msgmodelinfo:update")
    public R update(@RequestBody SysMsgModelInfoEntity msgModelInfo,@CurrentUser SysUserEntity user) {
    	msgModelInfo.setUpdateUser(user.getId());
    	msgModelInfo.setUpdateTime(new Date());
        int result=msgModelInfoService.update(msgModelInfo);
		if(result>0){
        	return R.ok();
        }else{
        	return R.failure();
        }
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("msgmodelinfo:delete")
    public R delete(@RequestBody String[] ids,@CurrentUser SysUserEntity user) {
    	Map<String, Object> params=new HashMap<String, Object>();
    	params.put("ids", ids);
    	params.put("updateUser", user.getId());
    	params.put("updateTime", new Date());
    	
        int result=msgModelInfoService.deleteLogicByMap(params);
		if(result>0){
        	return R.ok();
        }else{
        	return R.failure();
        }
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<SysMsgModelInfoEntity> list = msgModelInfoService.queryList(params);
        return R.ok().put("list", list);
    }
}
